package com.iterator.iface.impl;

import com.iterator.iface.Iterator;

import java.util.List;

public class IteratorImpl implements Iterator {

    private List<Object> list = null;

    private int index = -1;

    public IteratorImpl(List<Object> list) {
        this.list = list;
    }

    @Override
    public Object first() {
        // 程序鲁棒性
        if ( list.isEmpty() )
            return null;
        return list.get(0);
    }

    @Override
    public Object next() {
        if ( hasNext() )
            return list.get( ++index );
        return null;
    }

    @Override
    public boolean hasNext() {
        if ( index < list.size() - 1 )
            return true;
        return false;
    }
}
